clear

* set working directory

use IndustryLevelFDI.dta, clear
********************************************************************************
*************************** Imputed Data ***************************************
********************************************************************************
#delimit ;
global covars="gwf_personal allexp gtime lgdpcap lpop lopenness grow 
incidencev413 meanreserves ldevelopingfdi asia americas easia ssa"; 
#delimit cr

set more off
****
! dir Industry*.csv /a-d /b > filelist.txt

* command started with "file"* execute lines 19-42 together
file open myfile using "filelist.txt", read
file read myfile line
import delimited `line',clear
xtset cowcode year
xtregar cub_*_gdp $covars, re
regsave $covars _cons using coefs.dta, ci level(95) replace
use coefs.dta, clear
gen im=substr("`line'",1, length("`line'")-4)
save coefs.dta, replace

file read myfile line
while r(eof)==0 {
 import delimited `line',clear
 xtset cowcode year
 xtregar cub_*_gdp $covars, re
 regsave $covars _cons using temp.dta, ci level(95) replace
 use temp.dta, clear
 gen im=substr("`line'",1, length("`line'")-4)
 append using coefs.dta
 save coefs.dta, replace
 file read myfile line
}
**
file close myfile

***
erase temp.dta

gen industry=substr(im, 10,2)
replace industry=subinstr(industry, "_", "", .) 
destring industry, replace force

gen imputation=substr(im, 12,3)
replace imputation=subinstr(imputation, "_", "", .) 
destring imputation, replace force
save coefs.dta, replace

********************************************************************************
************************ Non-Imputed Data***************************************
********************************************************************************
use IndustryLevelFDI.dta, clear
xtset cowcode year

local replace "replace" 
foreach var of varlist cub_*_gdp {
 xtregar `var'  $covars, re
 regsave gwf_personal using coefs_nonimputed.dta, ci level(95) `replace'
 local replace "append"
 }
 *

